﻿using System;
using System.Data;
using System.Web.UI.WebControls;
using BLL;
using Utils;
namespace UI.ModEmployee
{
    public partial class EmpPassedList : System.Web.UI.Page
    {
        EmpPassedBiz empPassedBiz = new EmpPassedBiz();       
        string empCode = "";
        string bTm = "";
        string eTm = "";
        string passedTypeName = "";
        string infoType = "";
        string account = "";
        DefDicBiz defDicBiz = new DefDicBiz();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (Request.Params["EmpCode"] != null) empCode = Request.Params["EmpCode"].ToString().Trim();
            if (Request.Params["BTime"] != null) bTm = Request.Params["BTime"].ToString().Trim();
            if (Request.Params["ETime"] != null) eTm = Request.Params["ETime"].ToString().Trim();
            if (Request.Params["PassedTypeName"] != null) passedTypeName = Request.Params["PassedTypeName"].ToString().Trim();
            if (Request.Params["InfoType"] != null) infoType = Request.Params["InfoType"].ToString().Trim();

            if (Session["user"] != null)
            {
                User user = Session["user"] as User;
                account = user.Account;
            }
            else
            {
                JSUtility.Alert(this, "您没有登录!请先登录。");
                return;
            }
            if (!IsPostBack)
            {
                defDicBiz.InitXMLDropDownList(ddlInfoType, "PassedInfoType.xml", "请选择");
                btnAdd.Attributes.Add("onclick", "javascript:ShowLink('EmpPassedAdd.aspx',800,550);");
                btnBatchAdd.Attributes.Add("onclick", "javascript:ShowLink('EmpPasseBatchdAdd.aspx',800,550);");
                // JSUtility.AddReset(btnClear);
                if (empCode != "")
                {
                    txtSerWord.Text = empCode;
                    if (bTm != "") txtBtime.Text = bTm;
                    if (eTm != "") txtEtime.Text = eTm;
                    defDicBiz.InitDropDownList("Admin_Passed_type", ddlPassedTypeName, passedTypeName);
                    BondGvList(empCode, bTm, eTm, passedTypeName, infoType);
                }
                else
                {
                    defDicBiz.InitDropDownList("Admin_Passed_type", ddlPassedTypeName, "");
                   DataTable dt= empPassedBiz.GetNoPassed();
                   string msg = "";
                   for (int i = 0; i < dt.Rows.Count; i++)
                   {
                       msg += dt.Rows[i]["EmpName"] + "(" + dt.Rows[i]["EmpCode"]+")\n";                   
                   }
                   msg += "以上正式员工没有转正信息！";
                   JSUtility.Alert(this, msg);
                }
            }
        }

        protected void btnEmSearch_Click(object sender, EventArgs e)
        {
            if (!AccountBiz.CheckRight(account, "EmpPassedList.aspx", RightChar.Ser))
            {
                JSUtility.Alert(this, "无权限！");
                return;
            }
            string serWord = txtSerWord.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            string passedTypeName = ddlPassedTypeName.SelectedItem.Text.Trim();
            string infoType = ddlInfoType.SelectedValue;
            if (ddlPassedTypeName.SelectedValue == "0") passedTypeName = "";
     
            if (serWord == "" && bTime == "" && eTime == "" )
            {
                bTime = System.DateTime.Now.AddMonths(-2).ToString("yyyy-MM-dd");
                eTime = System.DateTime.Now.ToString("yyyy-MM-dd");
            }
            if (StringUtility.GetDiffDays(bTime, eTime) > XmlUtility.GetNumFormConfig("daysOfSearch"))
            {
                JSUtility.Alert(this, "查询日期间隔不能大于" + XmlUtility.GetNumFormConfig("daysOfSearch") + "天！");
                return;
            }
            BondGvList(serWord, bTime, eTime, passedTypeName, infoType);

        }

        protected void BondGvList(string serWord, string bTime, string eTime, string passedTypeName, string infoType)
        {
            DataTable dt = empPassedBiz.GetLists(serWord, bTime, eTime, passedTypeName, infoType);
         
            if (dt.Rows.Count > 0)
            {
                lbAmount.Text = "合计:    " + dt.Rows.Count;
            }
            else
            {
                lbAmount.Text = "";
            }
            //DataRow dr = dt.NewRow();
            //dr[9] = "合计:";
            //dr[10] = dt.Rows.Count;
            //dt.Rows.Add(dr);
            gvList.DataSource = dt;
            gvList.DataBind();


        }

       

        //protected void btnPrint_Click(object sender, EventArgs e)
        //{
        //    ToolUtility.Printer("转正信息表", gvList);
        //}
       
        //protected void btnExcel_Click(object sender, EventArgs e)
        //{
        //    string serWord = txtSerWord.Text.Trim();
        //    string bTime = txtBtime.Text.Trim();
        //    string eTime = txtEtime.Text.Trim();
        //    string passedTypeName = ddlPassedTypeName.SelectedItem.Text.Trim();
        //    if (ddlPassedTypeName.SelectedValue == "0") passedTypeName = "";
        //    ExcelUtility.ExportSqlToExcel(employeeBiz.GetPassedSQL(serWord, bTime, eTime, passedTypeName), XmlUtility.GetConnFormConfig());
        //}

       
        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#F3F8F8'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
            }
        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {
            if (!AccountBiz.CheckRight(account, "EmpPassedList.aspx", RightChar.Out))
            {
                JSUtility.Alert(this, "无权限！");
                return;
            }
            string serWord = txtSerWord.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            string passedTypeName = ddlPassedTypeName.SelectedItem.Text.Trim();
            if (ddlPassedTypeName.SelectedValue == "0") passedTypeName = "";
            string infoType = ddlInfoType.SelectedValue;
            ExcelUtility.ExportDsToXls(this, empPassedBiz.GetLists(serWord, bTime, eTime, passedTypeName, infoType), "Passed.xls");
        }
    }
}